package elijah.base.utils;

import android.app.Dialog;
import android.content.Context;

import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.interfaces.OnConfirmListener;


public class DialogUtils {


    public static void dismiss(Dialog pd) {
        try {
            if (pd != null && pd.isShowing()) pd.dismiss();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void dismiss(BasePopupView pro) {
        try {
            if (pro != null)
                pro.dismiss();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static BasePopupView showConfirmDialog(Context context, String content, OnConfirmListener callback) {
        return showConfirmDialog(context, 0.4f, content, callback);
    }

    public static BasePopupView showConfirmDialog(Context context, float width, String content, OnConfirmListener callback) {
        return new XPopup.Builder(context).popupWidth(DensityUtils.getWidthPxRatio(width)).asConfirm("提示", content, callback).show();
    }
}
